<template>
  <div>
    我是子组件：{{ $store.getters.getCount }}
    <br />
    {{ getCount }}
    <br>
    state:{{ count }}
    <br />
    <button @click="incr">财产增长</button>
  </div>
</template>

<script>
import { INCR_COUNT } from "../../store/constant";

// 写在计算属性中
import { mapGetters,mapState } from "vuex";

export default {
  data() {
    return {};
  },
  computed: {
    /* ...mapGetters({
      getCount: "getCount",
    }) */
    ...mapGetters(["getCount"]),
    ...mapState(['count'])
  },
  mounted() {
    // console.log(mapGetters(['getCount']))
    /* console.log(
      mapGetters({
        getCount: "getCount",
      })
    ); */
  },
  methods: {
    incr() {
      //this.$store.state.count = 200
      // 发送同步的命令，让全局状态修改
      // 参数1 命令名称
      // 参数2 命令传的参数，可选
      // this.$store.commit("incr");
      this.$store.commit(INCR_COUNT,100);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
